/**
*  \file var_tbl.c
*
*  \brief
*
*  \authors Dajin Li  dajin.li@linde-.de
*
*
*
*/

/*===============================================[ private includes  ]================================================*/
#include "var_tbl.h"
#include "CAN.h"
#include "CAN_canopen.h"
#include "switch.h"
#include "Display.h"
#include "hourmeter.h"
#include "resource.h"
#include "pwm.h"
#include "AnalogInput.h"
#include "icons.h"
#include "menu.h"
#include "bdi.h"
//#include "CAN1_J1939.h"
//#include "timestamp.h"

/*===============================================[ private defines   ]================================================*/
#define MIN_ENG_SPD                        1000
#define MAX_ENG_SPD                        5000
#define MAINTENANCE_HOURS                  1000
#define MAINTENANCE_DAYS                   180
#define VAR_TRUCK_SN_INDEX                 1
#define VAR_KEYON_HOURMETER_INDEX          2
#define VAR_BRAND_ID_INDEX                 3
#define VAR_SERIAL_NUMBER_INDEX            16
#define VAR_DATE_CODE_INDEX                17
#define VAR_HW_VER_INDEX                   18
#define VAR_TRUCK_ID_INDEX                 19
#define OSHA_MSG_NUMBER                    40
#define CUSTOMIZED_OSHA_MSG_LEGNTH         100


/*===============================================[ private datatypes ]================================================*/

/*===============================================[ private variables ]================================================*/
//static char controller_type[6];
//static char flasher_version[12];
static u16  diag_version = 1000;
static u8 software_module = 0x01; // 0x01, applicaiton, 0x00 bootblock, 0x05 KudOS,
//static u8 lift_software_module = 0x02; // 0x01, applicaiton, 0x00 bootblock, 0x05 KudOS,
//static char truck_sn[4] = {1, 2, 3, 4};
static char ecu_name[4] = {'T', '5', '1',  0x00};
//static char zapi_ecu_name[] = "ZP";
static char osha_msg_31[CUSTOMIZED_OSHA_MSG_LEGNTH] = "Customized message!";
static char osha_msg_32[CUSTOMIZED_OSHA_MSG_LEGNTH] = "Customized message!";
static char osha_msg_33[CUSTOMIZED_OSHA_MSG_LEGNTH] = "Customized message!";
static char osha_msg_34[CUSTOMIZED_OSHA_MSG_LEGNTH] = "Customized message!";
static char osha_msg_35[CUSTOMIZED_OSHA_MSG_LEGNTH] = "Customized message!";
static char osha_msg_36[CUSTOMIZED_OSHA_MSG_LEGNTH] = "Customized message!";
static char osha_msg_37[CUSTOMIZED_OSHA_MSG_LEGNTH] = "Customized message!";
static char osha_msg_38[CUSTOMIZED_OSHA_MSG_LEGNTH] = "Customized message!";
static char osha_msg_39[CUSTOMIZED_OSHA_MSG_LEGNTH] = "Customized message!";
static char osha_msg_40[CUSTOMIZED_OSHA_MSG_LEGNTH] = "Customized message!";
static s16 first_variable = {0};
s16 test_data = 0;
static s16 last_variable = {0};
//static s16 diag_res = 0;


/*===============================================[ public variables  ]================================================*/
u32 fault_status = PIN_CODE_FAULT;
u32 fault_status_prev = PIN_CODE_FAULT;
char hardware_id[12] = {0x31, 0x32,0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x30, 0x00};
u32 software_version = 2;
char disp_serial_number[16] = {0x30, 0x30, 0x30, 0x30, 0x30, 0x30,0x30, 0x30, 0x30,0x30, 0x30, 0x30,0x30, 0x30, 0x30, 0x00};
char truck_serial_number[13] = {0x30, 0x30, 0x30, 0x30, 0x30, 0x30,0x30, 0x30, 0x30,0x30, 0x30, 0x30,0x00};
char last_part_number[12];
char part_number[12] = {0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00};
// ----------------- BDI -----------------
s16 BDI_cutvpc;         // Param volts per cell at cutoff (0%) or actually 20% residual capacity 1.83 - 2.05 default 1.99
s16 BDI_mode;           // Param display mode for battery meter - options like % and HrsRem

u16 brand_id;
u8 truck_type;
u32 default_reset;
u16 error_reset;
u16 lcd_test = 0;
u32 active_osha_1;
u32 active_osha_2;
u8 osha_msg_showed;
u8 total_osha_msg;
u8 osha_msg_show_index[OSHA_MSG_NUMBER];
u16 DispDate;
u32 DispTime;
u32 truck_id = 0x00; 
s32 Eng_Speed;
s16 steer_angle;
u16 wheel_radius;
u16 traction_battery_capacity;
u16 area_speed_limit;  // this speed value will save to eeprom

u8 cal_stop;
char software_id[13];

u32 ComponentWorkTime;
u32 ServiceByHours;
u32 ServiceByDate;
u16 ServicePresetHours;
u16 ServicePresetDays;
u32 SetHourameter;
u8 Language;
u32 DateCurrent;
u32 TimeCurrent;
u8 Battery;
u8 ReferenceVoltage;
u8 CutOff;
u16 DigicodeTempValue;
u8 StandByTime;
u16 BatteryVoltage;
u16 DigicodeAdministrator;
u16 WheelPosition;
u32 DigicodeArray1Value;
u32 DigicodeArray2Value;
u32 DigicodeArray3Value;
u32 DigicodeArray4Value;
u32 DigicodeArray5Value;
u32 DigicodeArray6Value;
u32 DigicodeArray7Value;
u32 DigicodeArray8Value;
char ServiceAddress[12] = {0};
char Notepad[12] = {0};
const s16 MAX_KWP_ECU_OBJECT_DEF = 11;

const kwp_data_st kwp_ecu_params[] =
{
  { &(hardware_id),              0x0B,     0,    0x80,    0, 0, 0 },      // 0,  hardware id
  { &(software_id),              0x0C,     0,    0x81,    0, 0, 0 },      // 1,  software id
  { &(software_version),         0x02,     0,    0x84,    0, 0, 0 },      // 2,  software version
  { &(ecu_name),                 0x03,     0,    0x85,    0, 0, 0 },      // 3,  ECU name,
  { &(first_variable),           0x00,     0,    0x86,    0, 0, 0 },      // 4,  can flasher version
  { &(diag_version),             0x02,     0,    0x87,    0, 0, 0 },      // 5,  diag version
  { &(disp_serial_number),       0x0F,     0,    0x88,    0, 0, 0 },      // 6,  hardware serial number
  { &(last_part_number),         0x0B,     0,    0x89,    0, 0, 0 },      // 7,  last part number
  { &(software_module),          0x01,     0,    0x8A,    0, 0, 0 },      // 8,  software modules,
  { &(first_variable),           0x00,     0,    0x8B,    0, 0, 0 },      // 9,  reserved
  { &(first_variable),           0x00,     0,    0x86,    0, 0, 0 },      // 10, reserved
  { &(last_variable),            0,        0,    0,       0, 0, 0 }       //
};

const s16 MAX_KWP_DATA_OBJECT_DEF = 256;                                                                                                                                                             //----------------wait for modify
kwp_data_st kwp_data_params[] =
{
   // Var                                       attr        e_addr    id       min                        max                     default
  { &(part_number),                             0x880B,     0,        0x00,    0,                         0,                      0,                     },// 0,   part number
  { &(truck_serial_number),                     0x880C,     67,       0x01,    0,                         0,                      0,                     },// 1,   truck serial id
  { &(first_variable),                          0,          0,        0x02,    0,                         0,                      0,                     },// 2,   reserved
  { &(brand_id),                                0x8802,     11,       0x03,    0,                         0,                      0,                     },// 3,   brand id
  { &(first_variable),                          0,          0,        0x04,    0,                         0,                      0,                     },// 4,   reserved
  { &(first_variable),                          0,          0,        0x05,    0,                         0,                      0,                     },// 5,   reserved
  { &(first_variable),                          0,          0,        0x06,    0,                         0,                      0,                     },// 6,   reserved
  { &(first_variable),                          0,          0,        0x07,    0,                         0,                      0,                     },// 7,   reserved
  { &(first_variable),                          0,          0,        0x08,    0,                         0,                      0,                     },// 8,   reserved
  { &(first_variable),                          0,          0,        0x09,    0,                         0,                      0,                     },// 9,   reserved
  { &(first_variable),                          0,          0,        0x0A,    0,                         0,                      0,                     },// 10,  reserved
  { &(first_variable),                          0,          0,        0x0B,    0,                         0,                      0,                     },// 11,  reserved
  { &(first_variable),                          0,          0,        0x0C,    0,                         0,                      0,                     },// 12,  reserved
  { &(first_variable),                          0,          0,        0x0D,    0,                         0,                      0,                     },// 13,  reserved
  { &(first_variable),                          0,          0,        0x0E,    0,                         0,                      0,                     },// 14,  reserved
  { &(first_variable),                          0,          0,        0x0F,    0,                         0,                      0,                     },// 15,  reserved
  { &(disp_serial_number),                      0x880F,     13,       0x10,    0,                         0,                      0,                     },// 16,  display serial number
  { &(date_code),                               0x8802,     28,       0x11,    0,                         0,                      0,                     },// 17,  reserved
  { &(hardware_revision),                       0x8802,     30,       0x12,    0,                         0,                      0,                     },// 18,  hardware version
  { &(truck_id),                                0x8804,     65,       0x13,    0,                         0,                      0,                     },// 19,  truck id
  { &(TechPwd_KWP),                             0x8802,     200,      0x14,    0,                         0,                      0,                     },// 20,  reserved
  { &(ServicePwd_KWP),                          0x8802,     204,      0x15,    0,                         0,                      0,                     },// 21,  reserved
  { &(first_variable),                          0x880B,     0,        0x16,    0,                         1,                      0,                     },// 22,  reserved
  { &(first_variable),                          0,          0,        0x17,    0,                         0,                      0,                     },// 23,  reserved
  { &(date_format),                             0x8801,     700,      0x18,    0,                         2,                      0,                     },// 24,  display date and time format, 0x00-YYMMDD/HHMMSS_24h,  0x01-YYMMDD/HHMMSS_12h,  0x02-DDMMYY/HHMMSS_24h
  { &(hardware_id),                             0x880B,     32,       0x19,    0,                         0,                      0,                     },// 26,  hardware id
  { &(first_variable),                          0,          0,        0x1A,    0,                         0,                      0,                     },// 26,  reserved
  { &(last_part_number),                        0x880B,     55,       0x1B,    0,                         0,                      0,                     },// 27,  last part number
  { &(ReferenceVoltage),                        0x8801,     288,      0x1C,    0,                         255,                    209,                   },// 28,  reference voltage for each cell
  { &(CutOff),                                  0x8801,     296,      0x1D,    0,                         100,                    20,                    },// 29,  cutoff battery volumn
  { &(ComponentWorkTime),                       0x8804,     112,      0x1E,    0,                         0,                      0,                     },// 30,  reserved
  { &(Notepad),                                 0x880B,     500,      0x1F,    0,                         0,                      0,                     },// 31,  reserved
  { &(DigicodeTempValue),                       0x8802,     500,      0x20,    0,                         3,                      0,                     },// 32,  reserved
  { &(StandByTime),                             0x8801,     508,      0x21,    0,                         0,                      0,                     },// 33,
  { &(BatteryVoltage),                          0x4802,     516,      0x22,    0,                         0,                      0,                     },// 34, 
  { &(DigicodeAdministrator),                   0x8802,     304,      0x23,    4369,                      17476,                  0x1234,                },// 35,  administrator login pin code, default is "1234"
  { &(first_variable),                          0,          0,        0x24,    0,                         0,                      0,                     },// 36,  reserved
  { &(WheelPosition),                           0x4802,     584,      0x25,    0,                         0,                      0,                     },// 37,  reserved
  { &(DigicodeArray1Value),                     0x8804,     600,      0x26,    0,                         0,                      0,                     },// 38,  user digi code group1
  { &(DigicodeArray2Value),                     0x8804,     604,      0x27,    0,                         0,                      0,                     },// 39,  user digi code group2
  { &(DigicodeArray3Value),                     0x8804,     608,      0x28,    0,                         0,                      0,                     },// 40,  user digi code group3
  { &(DigicodeArray4Value),                     0x8804,     612,      0x29,    0,                         0,                      0,                     },// 41,  user digi code group4
  { &(DigicodeArray5Value),                     0x8804,     616,      0x2A,    0,                         0,                      0,                     },// 42,  user digi code group5
  { &(DigicodeArray6Value),                     0x8804,     620,      0x2B,    0,                         0,                      0,                     },// 43,  user digi code group6
  { &(DigicodeArray7Value),                     0x8804,     624,      0x2C,    0,                         0,                      0,                     },// 44,  user digi code group7
  { &(DigicodeArray8Value),                     0x8804,     628,      0x2D,    0,                         0,                      0,                     },// 45,  user digi code group8
  { &(Battery),                                 0x8801,     280,      0x2E,    0,                         0,                      0,                     },// 46,  reserved
  { &(ServiceByHours),                          0x8804,     216,      0x2F,    0,                         60000,                  10000,                 },// 47,  Service time, xxh
  { &(ServiceByDate),                           0x8804,     224,      0x30,    0,                         0,                      0 ,                    },// 48,  
  { &(ServicePresetHours),                      0x8802,     232,      0x31,    0,                         100,                    0,                     },// 49,  Service preset hour, xxh
  { &(ServicePresetDays),                       0x8802,     240,      0x32,    0,                         0,                      0,                     },// 49,  
  { &(ServiceAddress),                          0x880B,     400,      0x33,    0,                         0,                      0,                     },// 51,  
  { &(SetHourameter),                           0x8804,     264,      0x34,    0,                         0,                      0,                     },// 51,  
  { &(Language),                                0x8801,     272,      0x35,    0,                         0,                      0,                     },// 53,  Language: 0x00--English; 0x01--Chinese
  { &(first_variable),                          0,          0,        0x36,    0,                         0,                      0,                     },// 54,  reserved
  { &(first_variable),                          0,          0,        0x37,    0,                         0,                      0,                     },// 55,  reserved
  { &(first_variable),                          0,          0,        0x38,    0,                         0,                      0,                     },// 56,  reserved
  { &(first_variable),                          0,          0,        0x39,    0,                         0,                      0,                     },// 57,  reserved
  { &(first_variable),                          0,          0,        0x3A,    0,                         0,                      0,                     },// 58,  reserved
  { &(first_variable),                          0,          0,        0x3B,    0,                         0,                      0,                     },// 59,  reserved
  { &(first_variable),                          0,          0,        0x3C,    0,                         0,                      0,                     },// 60,  reserved
  { &(first_variable),                          0,          0,        0x3D,    0,                         0,                      0,                     },// 61,  reserved
  { &(first_variable),                          0,          0,        0x3E,    0,                         0,                      0,                     },// 62,  reserved
  { &(first_variable),                          0,          0,        0x3F,    0,                         0,                      0,                     },// 63,  reserved
  { &(first_variable),                          0,          0,        0x40,    0,                         0,                      0,                     },// 64,  reserved
  { &(first_variable),                          0,          0,        0x41,    0,                         0,                      0,                     },// 65,  reserved
  { &(first_variable),                          0,          0,        0x42,    0,                         0,                      0,                     },// 66,  reserved
  { &(first_variable),                          0,          0,        0x43,    0,                         0,                      0,                     },// 67,  reserved
  { &(first_variable),                          0,          0,        0x44,    0,                         0,                      0,                     },// 68,  reserved
  { &(first_variable),                          0,          0,        0x45,    0,                         0,                      0,                     },// 69,  reserved
  { &(first_variable),                          0,          0,        0x46,    0,                         0,                      0,                     },// 70,  reserved
  { &(first_variable),                          0,          0,        0x47,    0,                         0,                      0,                     },// 71,  reserved
  { &(first_variable),                          0,          0,        0x48,    0,                         0,                      0,                     },// 72,  reserved
  { &(first_variable),                          0,          0,        0x49,    0,                         0,                      0,                     },// 73,  reserved
  { &(first_variable),                          0,          0,        0x4A,    0,                         0,                      0,                     },// 74,  reserved
  { &(first_variable),                          0,          0,        0x4B,    0,                         0,                      0,                     },// 75,  reserved
  { &(first_variable),                          0,          0,        0x4C,    0,                         0,                      0,                     },// 76,  reserved
  { &(first_variable),                          0,          0,        0x4D,    0,                         0,                      0,                     },// 77,  reserved
  { &(first_variable),                          0,          0,        0x4E,    0,                         0,                      0,                     },// 78,  reserved
  { &(first_variable),                          0,          0,        0x4F,    0,                         0,                      0,                     },// 79,  reserved
  { &(first_variable),                          0,          0,        0x50,    0,                         0,                      0,                     },// 80,  reserved
  { &(first_variable),                          0,          0,        0x51,    0,                         0,                      0,                     },// 81,  reserved
  { &(first_variable),                          0,          0,        0x52,    0,                         0,                      0,                     },// 82,  reserved
  { &(Hrm_Struct.HM4_value),                    0x8804,     114,      0x53,    0,                         0,                      0,                     },// 83,  reserved
  { &(Hrm_Struct.HM3_value),                    0x8804,     118,      0x54,    0,                         0,                      0,                     },// 84,  Truck work time
  { &(Hrm_Struct.HM2_value),                    0x8804,     122,      0x55,    0,                         0,                      0,                     },// 85,  reserved
  { &(Hrm_Struct.HM1_value),                    0x8804,     126,      0x56,    0,                         0,                      0,                     },// 86,  reserved
  { &(first_variable),                          0,          7522,     0x57,    0,                         0,                      0,                     },// 87,  reserved
  { &(first_variable),                          0,          7538,     0x58,    0,                         0,                      0,                     },// 88,  reserved
  { &(first_variable),                          0,          7554,     0x59,    0,                         0,                      0,                     },// 89,  reserved
  { &(first_variable),                          0,          7570,     0x5A,    0,                         0,                      0,                     },// 90,  reserved
  { &(first_variable),                          0,          7586,     0x5B,    0,                         0,                      0,                     },// 91,  reserved
  { &(first_variable),                          0,          7602,     0x5C,    0,                         0,                      0,                     },// 92,  reserved
  { &(first_variable),                          0,          7618,     0x5D,    0,                         0,                      0,                     },// 93,  reserved
  { &(first_variable),                          0,          7634,     0x5E,    0,                         0,                      0,                     },// 94,  reserved
  { &(first_variable),                          0,          7650,     0x5F,    0,                         0,                      0,                     },// 95,  reserved
  { &(first_variable),                          0,          7666,     0x60,    0,                         0,                      0,                     },// 96,  reserved
  { &(first_variable),                          0,          7682,     0x61,    0,                         0,                      0,                     },// 97,  reserved
  { &(first_variable),                          0,          7698,     0x62,    0,                         0,                      0,                     },// 98,  reserved
  { &(first_variable),                          0,          7714,     0x63,    0,                         0,                      0,                     },// 99,  reserved
  { &(first_variable),                          0,          7730,     0x64,    0,                         0,                      0,                     },// 100, reserved
  { &(first_variable),                          0,          7746,     0x65,    0,                         0,                      0,                     },// 101, reserved
  { &(first_variable),                          0,          7762,     0x66,    0,                         0,                      0,                     },// 102, reserved
  { &(first_variable),                          0,          0,        0x67,    0,                         0,                      0,                     },// 103, reserved
  { &(first_variable),                          0,          0,        0x68,    0,                         0,                      0,                     },// 104, reserved
  { &(DateCurrent),                             0x8004,     0,        0x69,    0,                         0,                      0,                     },// 105, Current data
  { &(TimeCurrent),                             0x8004,     0,        0x6A,    0,                         0,                      0,                     },// 106, Current time
  { &(first_variable),                          0,          0,        0x6B,    0,                         0,                      0,                     },// 104, reserved
  { &(first_variable),                          0,          0,        0x6C,    0,                         0,                      0,                     },// 104, reserved
  { &(first_variable),                          0,          0,        0x6D,    0,                         0,                      0,                     },// 104, reserved
  { &(first_variable),                          0,          0,        0x6E,    0,                         0,                      0,                     },// 104, reserved
  { &(first_variable),                          0,          0,        0x6F,    0,                         0,                      0,                     },// 104, reserved
  { &(first_variable),                          0,          99,       0x70,    0,                         255,                    0,                     },// 112, reserved 
  { &(first_variable),                          0,          0,        0x71,    0,                         0,                      0,                     },// 113, reserved
  { &(first_variable),                          0,          0,        0x72,    0,                         0,                      0,                     },// 114, reserved
  { &(first_variable),                          0,          0,        0x73,    0,                         0,                      0,                     },// 115, reserved
  { &(first_variable),                          0,          0,        0x74,    0,                         0,                      0,                     },// 116, reserved
  { &(first_variable),                          0,          0,        0x75,    0,                         0,                      0,                     },// 117, reserved
  { &(first_variable),                          0,          0,        0x76,    0,                         0,                      0,                     },// 118, reserved
  { &(first_variable),                          0,          0,        0x77,    0,                         0,                      0,                     },// 119, reserved
  { &(first_variable),                          0,          0,        0x78,    0,                         0,                      0,                     },// 120, reserved
  { &(first_variable),                          0,          0,        0x79,    0,                         0,                      0,                     },// 121, reserved
  { &(first_variable),                          0,          0,        0x7A,    0,                         0,                      0,                     },// 122, reserved
  { &(first_variable),                          0,          0,        0x7B,    0,                         0,                      0,                     },// 123, reserved
  { &(LCD_Bklight),                             0xCC01,     214,      0x7C,    1,                         100,                    50,                    },// 124, lcd_bklight
  { &(first_variable),                          0,          7266,     0x7D,    0,                         0,                      0,                     },// 125, reserved
  { &(first_variable),                          0,          7282,     0x7E,    0,                         0,                      0,                     },// 126, reserved
  { &(first_variable),                          0,          7298,     0x7F,    0,                         0,                      0,                     },// 127, reserved
  { &(first_variable),                          0,          7314,     0x80,    0,                         0,                      0,                     },// 128, reserved
  { &(first_variable),                          0,          7330,     0x81,    0,                         0,                      0,                     },// 129, reserved
  { &(first_variable),                          0,          7346,     0x82,    0,                         0,                      0,                     },// 130, reserved
  { &(first_variable),                          0,          7362,     0x83,    0,                         0,                      0,                     },// 131, reserved
  { &(first_variable),                          0,          7378,     0x84,    0,                         0,                      0,                     },// 132, reserved
  { &(first_variable),                          0,          7394,     0x85,    0,                         0,                      0,                     },// 133, reserved
  { &(first_variable),                          0,          7410,     0x86,    0,                         0,                      0,                     },// 134, reserved
  { &(first_variable),                          0,          7426,     0x87,    0,                         0,                      0,                     },// 135, reserved
  { &(first_variable),                          0,          7442,     0x88,    0,                         0,                      0,                     },// 136, reserved
  { &(first_variable),                          0,          7458,     0x89,    0,                         0,                      0,                     },// 137, reserved
  { &(first_variable),                          0,          7474,     0x8A,    0,                         0,                      0,                     },// 138, reserved
  { &(first_variable),                          0,          7490,     0x8B,    0,                         0,                      0,                     },// 139, reserved
  { &(first_variable),                          0,          7506,     0x8C,    0,                         0,                      0,                     },// 140, reserved
  { &(first_variable),                          0,          0,        0x8D,    0,                         0,                      0,                     },// 141, reserved
  { &(first_variable),                          0,          0,        0x8E,    0,                         0,                      0,                     },// 142, reserved
  { &(first_variable),                          0,          0,        0x8F,    0,                         0,                      0,                     },// 143, reserved
  { &(first_variable),                          0,          0,        0x90,    0,                         0,                      0,                     },// 145, reserved
  { &(first_variable),                          0,          0,        0x91,    0,                         0,                      0,                     },// 145, reserved
  { &(first_variable),                          0,          0,        0x92,    0,                         0,                      0,                     },// 146, reserved
  { &(first_variable),                          0,          0,        0x93,    0,                         0,                      0,                     },// 147, reserved
  { &(first_variable),                          0,          0,        0x94,    0,                         0,                      0,                     },// 148, reserved
  { &(first_variable),                          0,          254,      0x95,    0,                         0,                      0,                     },// 149, reserved
  { &(first_variable),                          0,          254,      0x96,    0,                         0,                      0,                     },// 150, reserved
  { &(first_variable),                          0,          0,        0x97,    0,                         0,                      0,                     },// 151, reserved
  { &(first_variable),                          0,          0,        0x98,    0,                         0,                      0,                     },// 152, reserved
  { &(first_variable),                          0,          0,        0x99,    0,                         0,                      0,                     },// 153, reserved
  { &(first_variable),                          0,          0,        0x9A,    0,                         0,                      0,                     },// 154, reserved
  { &(first_variable),                          0,          0,        0x9B,    0,                         0,                      0,                     },// 155, reserved
  { &(first_variable),                          0,          0,        0x9C,    0,                         0,                      0,                     },// 156, reserved
  { &(first_variable),                          0,          0,        0x9D,    0,                         0,                      0,                     },// 157, reserved
  { &(first_variable),                          0,          0,        0x9E,    0,                         0,                      0,                     },// 158, reserved
  { &(first_variable),                          0,          0,        0x9F,    0,                         0,                      0,                     },// 159, reserved
  { &(first_variable),                          0,          0,        0xA0,    0,                         0,                      0,                     },// 160, reserved
  { &(first_variable),                          0,          0,        0xA1,    0,                         0,                      0,                     },// 161, reserved
  { &(first_variable),                          0,          0,        0xA2,    0,                         0,                      0,                     },// 162, reserved
  { &(first_variable),                          0,          0,        0xA3,    0,                         0,                      0,                     },// 163, reserved
  { &(first_variable),                          0,          0,        0xA4,    0,                         0,                      0,                     },// 164, reserved
  { &(first_variable),                          0,          216,      0xA5,    MIN_TRACTION_SPD_KMH,      MAX_TRACTION_SPD_KMH,   50,                    },// 165, reserved
  { &(first_variable),                          0,          218,      0xA6,    MIN_TRACTION_SPD_KMH,      MAX_TRACTION_SPD_KMH,   200,                   },// 166, reserved
  { &(first_variable),                          0,          220,      0xA7,    MIN_TRACTION_SPD_KMH,      MAX_TRACTION_SPD_KMH,   200,                   },// 167, reserved
  { &(first_variable),                          0,          222,      0xA8,    0,                         0xFFFF,                 0,                     },// 168, reserved
  { &(first_variable),                          0,          224,      0xA9,    0,                         0xFFFF,                 0,                     },// 169, reserved
  { &(first_variable),                          0,          226,      0xAA,    0,                         0xFFFF,                 0,                     },// 170, reserved
  { &(first_variable),                          0,          228,      0xAB,    0,                         0xFFFF,                 0,                     },// 171, reserved
  { &(first_variable),                          0,          230,      0xAC,    0,                         0xFFFF,                 0,                     },// 172, reserved
  { &(first_variable),                          0,          232,      0xAD,    0,                         0xFFFF,                 0,                     },// 173, reserved
  { &(first_variable),                          0,          234,      0xAE,    0,                         0xFFFF,                 0,                     },// 174, reserved
  { &(first_variable),                          0,          236,      0xAF,    0,                         0xFFFF,                 0,                     },// 175, reserved
  { &(first_variable),                          0,          238,      0xB0,    0,                         0xFFFF,                 0,                     },// 176, reserved
  { &(first_variable),                          0,          240,      0xB1,    0,                         0xFFFF,                 0,                     },// 177, reserved
  { &(first_variable),                          0,          242,      0xB2,    0,                         0xFFFF,                 0,                     },// 178, reserved
  { &(first_variable),                          0,          244,      0xB3,    0,                         0xFFFF,                 0,                     },// 179, reserved
  { &(first_variable),                          0,          246,      0xB4,    0,                         0xFFFF,                 0,                     },// 180, reserved
  { &(first_variable),                          0,          248,      0xB5,    0,                         0xFFFF,                 0,                     },// 181, reserved
  { &(first_variable),                          0,          250,      0xB6,    0,                         0xFFFF,                 0,                     },// 182, reserved
  { &(first_variable),                          0,          252,      0xB7,    0,                         0xFFFF,                 0,                     },// 183, reserved
  { &(first_variable),                          0,          254,      0xB8,    0,                         0,                      0x0000,                },// 184, reserved
  { &(first_variable),                          0,          256,      0xB9,    0,                         5,                      0,                     },// 185, reserved
  { &(first_variable),                          0,          257,      0xBA,    0,                         50,                     0,                     },// 186, reserved
  { &(first_variable),                          0,          7009,     0xBB,    0,                         0,                      0,                     },// 187, reserved
  { &(first_variable),                          0,          7025,     0xBC,    0,                         0,                      0,                     },// 188, reserved
  { &(first_variable),                          0,          7041,     0xBD,    0,                         0,                      0,                     },// 189, reserved
  { &(first_variable),                          0,          7057,     0xBE,    0,                         0,                      0,                     },// 190, reserved
  { &(first_variable),                          0,          7073,     0xBF,    0,                         0,                      0,                     },// 191, reserved
  { &(first_variable),                          0,          7089,     0xC0,    0,                         0,                      0,                     },// 192, reserved
  { &(first_variable),                          0,          7105,     0xC1,    0,                         0,                      0,                     },// 193, reserved
  { &(first_variable),                          0,          7121,     0xC2,    0,                         0,                      0,                     },// 194, reserved
  { &(first_variable),                          0,          7137,     0xC3,    0,                         0,                      0,                     },// 195, reserved
  { &(BDI_vbatt_cal[0]),                        0xC802,     176,      0xC4,    BAT_CAL_MIN,               BAT_CAL_MAX,            BAT_CAL_DEF,                     },// 196, reserved
  { &(first_variable),                          0,          7169,     0xC5,    0,                         0,                      0,                     },// 197, reserved
  { &(first_variable),                          0,          7185,     0xC6,    0,                         0,                      0,                     },// 198, reserved
  { &(first_variable),                          0,          7201,     0xC7,    0,                         0,                      0,                     },// 199, reserved
  { &(first_variable),                          0,          7217,     0xC8,    0,                         0,                      0,                     },// 200, reserved
  { &(first_variable),                          0,          7233,     0xC9,    0,                         0,                      0,                     },// 201, reserved
  { &(first_variable),                          0,          7249,     0xCA,    0,                         0,                      0,                     },// 202, reserved
  { &(first_variable),                          0,          259,      0xCB,    0,                         2,                      0,                     },// 203, reserved
  { &(first_variable),                          0,          0,        0xCC,    0,                         0,                      0,                     },// 204, reserved
  { &(first_variable),                          0,          261,      0xCD,    -999,                      MAX_MAINTENANCE_HOURS,  MAINTENANCE_HOURS,     },// 205, reserved
  { &(first_variable),                          0,          263,      0xCE,    -999,                      MAX_MAINTENANCE_HOURS,  MAINTENANCE_HOURS,     },// 206, reserved
  { &(first_variable),                          0,          265,      0xCF,    -999,                      MAX_MAINTENANCE_HOURS,  MAINTENANCE_HOURS,     },// 207, reserved
  { &(first_variable),                          0,          267,      0xD0,    -999,                      MAX_MAINTENANCE_HOURS,  MAINTENANCE_HOURS,     },// 208, reserved
  { &(first_variable),                          0,          0,        0xD1,    0,                         0,                      0,                     },// 209, reserved
  { &(first_variable),                          0,          0,        0xD2,    0,                         0,                      0,                     },// 210, reserved
  { &(first_variable),                          0,          269,      0xD3,    MIN_STATUS_SEL,            MAX_STATUS_SEL,         1,                     },// 211, reserved
  { &(first_variable),                          0,          270,      0xD4,    MIN_STATUS_SEL,            MAX_STATUS_SEL,         3,                     },// 212, reserved
  { &(first_variable),                          0,          271,      0xD5,    -999,                      MAX_MAINTENANCE_DAYS,   MAINTENANCE_DAYS,      },// 213, reserved
  { &(first_variable),                          0,          273,      0xD6,    -999,                      MAX_MAINTENANCE_DAYS,   MAINTENANCE_DAYS,      },// 214, reserved
  { &(first_variable),                          0,          275,      0xD7,    -999,                      MAX_MAINTENANCE_DAYS,   MAINTENANCE_DAYS,      },// 215, reserved
  { &(first_variable),                          0,          277,      0xD8,    -999,                      MAX_MAINTENANCE_DAYS,   MAINTENANCE_DAYS,      },// 216, reserved
  { &(first_variable),                          0,          279,      0xD9,    0,                         100,                    50,                    },// 217, reserved
  { &(first_variable),                          0,          281,      0xDA,    0,                         100,                    50,                    },// 218, reserved
  { &(first_variable),                          0,          283,      0xDB,    1,                         100,                    20,                    },// 219, reserved
  { &(first_variable),                          0,          285,      0xDC,    1,                         20,                     2,                     },// 220, reserved
  { &(first_variable),                          0,          287,      0xDD,    10,                        200,                    40,                    },// 221, reserved
  { &(first_variable),                          0,          290,      0xDE,    0,                         0,                      0,                     },// 222, reserved
  { &(first_variable),                          0,          292,      0xDF,    MIN_TRACTION_SPD_KMH,      MAX_TRACTION_SPD_KMH,   160,                   },// 223, reserved
  { &(first_variable),                          0,          294,      0xE0,    100,                       3000,                   400,                   },// 224, reserved
  { &(first_variable),                          0,          7778,     0xE1,    0,                         0,                      0,                     },// 225, reserved
  { &(first_variable),                          0,          7794,     0xE2,    0,                         0,                      0,                     },// 226, reserved
  { &(first_variable),                          0,          7810,     0xE3,    0,                         0,                      0,                     },// 227, reserved
  { &(first_variable),                          0,          7826,     0xE4,    0,                         0,                      0,                     },// 228, reserved
  { &(first_variable),                          0,          7842,     0xE5,    0,                         0,                      0,                     },// 229, reserved
  { &(first_variable),                          0,          7858,     0xE6,    0,                         0,                      0,                     },// 230, reserved
  { &(first_variable),                          0,          7874,     0xE7,    0,                         0,                      0,                     },// 231, reserved
  { &(first_variable),                          0,          7890,     0xE8,    0,                         0,                      0,                     },// 232, reserved
  { &(first_variable),                          0,          7906,     0xE9,    0,                         0,                      0,                     },// 233, reserved
  { &(first_variable),                          0,          7922,     0xEA,    0,                         0,                      0,                     },// 234, reserved
  { &(first_variable),                          0,          7938,     0xEB,    0,                         0,                      0,                     },// 235, reserved
  { &(first_variable),                          0,          7954,     0xEC,    0,                         0,                      0,                     },// 236, reserved
  { &(first_variable),                          0,          7970,     0xED,    0,                         0,                      0,                     },// 237, reserved
  { &(first_variable),                          0,          7986,     0xEE,    0,                         0,                      0,                     },// 238, reserved
  { &(first_variable),                          0,          8002,     0xEF,    0,                         0,                      0,                     },// 239, reserved
  { &(first_variable),                          0,          8018,     0xF0,    0,                         0,                      0,                     },// 240, reserved
  { &(first_variable),                          0,          296,      0xF1,    0,                         12000,                  3170,                  },// 241, reserved
  { &(first_variable),                          0,          298,      0xF2,    0,                         12000,                  7700,                  },// 242, reserved
  { &(first_variable),                          0,          300,      0xF3,    0,                         12000,                  10000,                 },// 243, reserved
  { &(first_variable),                          0,          302,      0xF4,    0,                         250,                    60,                    },// 244, reserved
  { &(first_variable),                          0,          304,      0xF5,    0,                         1000,                   130,                   },// 245, reserved
  { &(first_variable),                          0,          306,      0xF6,    0,                         1000,                   270,                   },// 246, reserved
  { &(first_variable),                          0,          308,      0xF7,    0,                         1000,                   340,                   },// 247, reserved
  { &(first_variable),                          0,          0,        0xF8,    0,                         0,                      0,                     },// 248, reserved
  { &(first_variable),                          0,          0,        0xF9,    0,                         0,                      0,                     },// 249, reserved
  { &(first_variable),                          0,          0,        0xFA,    0,                         0,                      0,                     },// 250, reserved
  { &(first_variable),                          0,          0,        0xFB,    0,                         0,                      0,                     },// 251, reserved
  { &(first_variable),                          0,          0,        0xFC,    0,                         0,                      0,                     },// 252, reserved
  { &(first_variable),                          0,          0,        0xFD,    0,                         0,                      0,                     },// 253, reserved
  { &(first_variable),                          0,          0,        0xFE,    0,                         0,                      0,                     },// 254, reserved
  { &(first_variable),                          0,          0,        0xFF,    0,                         0,                      0,                     },// 255, reserved
  { &(last_variable),                           0,          0,        0,       0,                         0,                      0,                     } // null
};

/* Global variables ---------------------------------------------------------*/
void *const osha_msg_table[] =
{
    (void *)(&osha_msg_1),                                              // 0,   osha message 1
    (void *)(&osha_msg_2),                                              // 1,   osha message 2
    (void *)(&osha_msg_3),                                              // 2,   osha message 3
    (void *)(&osha_msg_4),                                              // 3,   osha message 4
    (void *)(&osha_msg_5),                                              // 4,   osha message 5
    (void *)(&osha_msg_6),                                              // 5,   osha message 6
    (void *)(&osha_msg_7),                                              // 6,   osha message 7
    (void *)(&osha_msg_8),                                              // 7,   osha message 8
    (void *)(&osha_msg_9),                                              // 8,   osha message 9
    (void *)(&osha_msg_10),                                             // 9,   osha message 10
    (void *)(&osha_msg_11),                                             // 10,  osha message 11
    (void *)(&osha_msg_12),                                             // 11,  osha message 12
    (void *)(&osha_msg_13),                                             // 12,  osha message 13
    (void *)(&osha_msg_14),                                             // 13,  osha message 14
    (void *)(&osha_msg_15),                                             // 14,  osha message 15
    (void *)(&osha_msg_16),                                             // 15,  osha message 16
    (void *)(&osha_msg_17),                                             // 16,  osha message 17 
    (void *)(&osha_msg_18),                                             // 17,  osha message 18
    (void *)(&osha_msg_19),                                             // 18,  osha message 19
    (void *)(&osha_msg_20),                                             // 19,  osha message 20
    (void *)(&osha_msg_21),                                             // 20,  osha message 21
    (void *)(&osha_msg_22),                                             // 21,  osha message 22 
    (void *)(&osha_msg_23),                                             // 22,  osha message 23
    (void *)(&osha_msg_24),                                             // 23,  osha message 24
    (void *)(&osha_msg_25),                                             // 24,  osha message 25
    (void *)(&osha_msg_26),                                             // 25,  osha message 26
    (void *)(&osha_msg_27),                                             // 26,  osha message 27
    (void *)(&osha_msg_28),                                             // 27,  osha message 28
    (void *)(&osha_msg_29),                                             // 28,  osha message 29
    (void *)(&osha_msg_30),                                             // 29,  osha message 30
    (void *)(&osha_msg_31),                                             // 30,  osha message 31
    (void *)(&osha_msg_32),                                             // 31,  osha message 32
    (void *)(&osha_msg_33),                                             // 32,  osha message 33
    (void *)(&osha_msg_34),                                             // 33,  osha message 34
    (void *)(&osha_msg_35),                                             // 34,  osha message 35
    (void *)(&osha_msg_36),                                             // 35,  osha message 36
    (void *)(&osha_msg_37),                                             // 36,  osha message 37
    (void *)(&osha_msg_38),                                             // 37,  osha message 38
    (void *)(&osha_msg_39),                                             // 38,  osha message 39
    (void *)(&osha_msg_40),                                             // 39,  osha message 40
    (void *)(&last_variable)
};

const int display_fault_max_obj_id = 9;

const Truck_fault_msg_st  Display_Fault_Msg_Descripiton[]=
{
 	{0x0101, (u8 *)display_fault_0101, 0, 0},      // 0 
	{0x0102, (u8 *)display_fault_0102, 0, 0},      // 1 
	{0x0103, (u8 *)display_fault_0103, 0, 0},      // 2 
	{0x0104, (u8 *)display_fault_0104, 0, 0},      // 3	
	{0x0105, (u8 *)display_fault_0105, 0, 0},      // 4	
	{0x0106, (u8 *)display_fault_0106, 0, 0},      // 5	
	{0x0261, (u8 *)display_fault_0261, 0, 0},      // 6 
	{0x0262, (u8 *)display_fault_0262, 0, 0},      // 7 	
	{0x0301, (u8 *)display_fault_0301, 0, 0}       // 8 
};



const char *const UnitsTable[] =
{
    "",                     // 0
    "Hz",                   // 1
    "%",                    // 2
    "~C",                   // 3
    "~",                    // 4
    "V",                    // 5
    "A",                    // 6
    "h",                    // 7
    "sec",                  // 8
};

/* Global variables ---------------------------------------------------------*/
const char*  const warning_str[]=
{   
    0,
    "Return to",                                       // 1, 
    "operating position.",                             // 2, 
    "Motor overtemp!",                                 // 3,                
    "Engine overtemp!",                                // 4,
    "Trans. overtemp!",                                // 5,
    "Service brake!",                                  // 6,
    "Controller fault!",                               // 7,
    "Hydraulic overtemp!",                             // 8,
    "Low oil pressure!",                               // 9,
    "Low fuel!",                                       // 10,
    "Battery charge low.",                             // 11,
    "Fasten belt!",                                    // 12
    "P",                                               // 13
    "D",                                               // 14
    "SPN-FMI:",                                        // 15
    "T",                                               // 16
    "L",                                               // 17
    "",                                                // 18
    "R",                                               // 19
    "B",                                               // 20
};

const char error_rfid264[]="Rfid tag error";
const char error_rfid777[]="Rfid signal error";
const char cn_error_rfid264[]="Rfid tag error";
const char cn_error_rfid777[]="Rfid signal error";
const char fr_error_rfid264[]="Rfid tag error";
const char fr_error_rfid777[]="Rfid signal error";
const char sp_error_rfid264[]="Rfid tag error";
const char sp_error_rfid777[]="Rfid signal error";


const s16 MAX_RFID_MAX_OBJECT_DEF = 2;
const Truck_fault_msg_st Rfid_Fault_Msg_Descripiton[] =
{
    {264,      (u8*)error_rfid264,      (u8*)cn_error_rfid264,      (u8*)fr_error_rfid264,      (u8*)sp_error_rfid264},//  1
    {777,      (u8*)error_rfid777,      (u8*)cn_error_rfid777,      (u8*)fr_error_rfid777,      (u8*)sp_error_rfid777},//  2
};

/*================================================[ inline functions ]================================================*/





/*===============================================[ private functions ]================================================*/
/*================================================[ public functions ]================================================*/


/***********************************************************************************************************************
*                             Copyright 2016 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/



